#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "commoditydelegate.h"
#include <QtSql>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    model = new CustomRelationalTableModel(ui->orderTv);
    //model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->setTable("wms_sale_order");
    model->setHeaderData(0, Qt::Horizontal, tr("Order ID"));
    model->setHeaderData(1, Qt::Horizontal, tr("Customer"));
    model->setRelation(1, QSqlRelation("wms_customer", "id", "name"));
    ui->orderTv->setItemDelegateForColumn(1, new QSqlRelationalDelegate());

    model->select();
    ui->orderTv->setModel(model);
    ui->orderTv->setSelectionBehavior(QAbstractItemView::SelectRows);
    //connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(accept()));
}

MainWindow::~MainWindow()
{
    delete ui;
}
